<template>
  <div class="container">
    <!-- // 审核功能Dialog -->
    <el-dialog
      title="题目审核"
      :visible="showReviewDialog"
      width="30%"
      @close="close"
    >
      <el-radio-group v-model="radioValue">
        <el-radio label="1">通过</el-radio>
        <el-radio label="2">拒绝</el-radio>
      </el-radio-group>
      <el-input
        v-model="suggestion"
        v-focus
        type="textarea"
        :rows="2"
        placeholder="请输入审核意见"
        style="margin-top: 20px"
      />
      <span slot="footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="check">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  name: 'QuestionCheck',
  directives: {
    focus: {
      inserted(el) {
        console.log(el)
        el.children[0].focus()
      },
      update(el) {
        el.children[0].focus()
      }
    }
  },
  props: {
    showReviewDialog: {
      type: Boolean,
      default: false
    },
    questions: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      radioValue: '1', // 绑定审核单选radio的值
      suggestion: '' // 审核意见
    }
  },
  methods: {
    close() {
      // 关闭弹窗
      this.$emit('update:showReviewDialog', false)
      this.suggestion = '' // 关闭弹窗的时候清空内容
    },
    // 确认审核
    async check() {
      if (!this.suggestion) {
        return this.$message({
          type: 'warning',
          message: '请输入审核意见'
        })
      }
      await choiceCheck({
        id: this.questions.id,
        chkState: +this.radioValue,
        chkRemarks: this.suggestion
      })
      // 关闭弹窗
      this.$emit('update:showReviewDialog', false)
      this.$message.success('操作成功')
      // 更新列表重新渲染
      this.$emit('updateList')
    }
  }
}
</script>

<style scoped lang='scss'></style>
